import java.io.*;
import java.util.*;

public class Main {
	BufferedReader bf;
	StringTokenizer st;
	StringBuilder output = new StringBuilder();
	
	int n,
		MAX_DISTANCE = 10000;
	int[][] w,
			d;
	
	public static void main(String[] args) {		
		Main main = new Main();
		main.beginProcess();
	}

	public void beginProcess() {
		bf = new BufferedReader(new InputStreamReader(System.in));
		int i, j;
		
		try {
			st = new StringTokenizer(bf.readLine());
			n = Integer.parseInt(st.nextToken());
			
			w = new int[n + 1][n + 1];
			d = new int[n + 1][n + 1];
			for(i = 1; i <= n; i++) {
				st = new StringTokenizer(bf.readLine());
				for(j = 1; j <= n; j++) {
					w[i][j] = Integer.parseInt(st.nextToken());
					if(w[i][j] == 1) {
						d[i][j] = w[i][j];
					} else {
						d[i][j] = MAX_DISTANCE;
					}
				}
			}
			
			floyd_warshall();

			System.out.print(output);
		}
		catch(Exception ex) {
			System.err.println(ex.toString());
		}
	}
	
	private void floyd_warshall() {
		int k,
			j,
			i;
		
		for(i = 1; i <= n; i++)
	        d[i][i] = 0;
		
		for(k = 1; k <= n; k++)
			for(i = 1; i <= n; i++)
				for(j = 1; j <= n; j++)
					if(d[i][k] + d[k][j] < d[i][j])
						d[i][j] = d[i][k] + d[k][j];
		
		for(i = 1; i <= n; i++)
			output.append((d[1][i] + 1) + "\n");
	}
	
}